﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace elmah2.core.loggers
{
  public class QueryData
  {
    public bool QuerySuccessful { get; set; }
    public List<object[]> RowData { get; set; }
    public Dictionary<string, int> FieldMappings { get; set; }
    public int RowCount { get { return RowData.Count; } }

    public QueryData()
    {
      FieldMappings = new Dictionary<string, int>();
      RowData = new List<object[]>();
      QuerySuccessful = false;
    }

    public bool HasMappingForField(string fieldName)
    {
      return FieldMappings.ContainsKey(fieldName.ToLower());
    }

    public object GetDataForRowField(int row, string field)
    {
      object toReturn = null;
      if (HasMappingForField(field) && RowData.Count > row)
      {
        toReturn = RowData[row][FieldMappings[field.ToLower()]];
      }

      return toReturn;
    }
  }
}
